package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.AdSensitiveDto;
import com.heima.model.common.dtos.ResponseResult;

import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.pojos.wemedia.WmChannel;
import com.heima.model.common.pojos.wemedia.WmSensitive;
import com.heima.wemedia.service.WmSensitiveService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/v1/sensitive")
@Slf4j
public class WmSensitiveController {
    @Autowired
    private WmSensitiveService wmSensitiveService;


    /**
     * 加载所有敏感词
     *
     * @return
     */
    @GetMapping("/list")
    public ResponseResult queryAll() {
        log.info("加载所有敏感词");
        List<WmSensitive> list = wmSensitiveService.list();
        return ResponseResult.okResult(list);
    }

    /**
     * 添加敏感词
     */
    @PostMapping("/save")
    public ResponseResult saveSensitive(@RequestBody AdSensitiveDto adSensitiveDto) {
        log.info("添加敏感词:{}", adSensitiveDto);
        return wmSensitiveService.saveSensitive(adSensitiveDto);
    }

    /**
     * 分页查询敏感词列表
     *
     * @param adSensitiveDto
     */
    @PostMapping("/list")
    public ResponseResult listSensitive(@RequestBody AdSensitiveDto adSensitiveDto) {
        log.info("分页查询敏感词列表:{}", adSensitiveDto);
        return wmSensitiveService.listSensitive(adSensitiveDto);
    }

    /**
     * 删除敏感词
     */
    @DeleteMapping("/del/{id}")
    public ResponseResult delSensitive(@PathVariable("id") Integer id) {
        log.info("删除敏感词:{}", id);
        return wmSensitiveService.delSensitive(id);
    }

    /**
     * 修改敏感词
     */
    @PostMapping("/update")
    public ResponseResult updateSensitive(@RequestBody AdSensitiveDto adSensitiveDto) {
        log.info("修改敏感词:{}", adSensitiveDto);
        return wmSensitiveService.updateSensitive(adSensitiveDto);
    }

}